package org.e_gold.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.e_gold.model.crawler.livescore.League;
import org.e_gold.util.Bet365;

@Entity
@Table(name = "event")
public class Event extends ValueObject implements Serializable, Bet365 {

	public static final String NAME = "name";

	private static final long serialVersionUID = 1L;

	private String name;

	@Id
	@GeneratedValue
	private Long id;

	@Column(name = "home_name")
	private String homeName;

	@Column(name = "away_name")
	private String awayName;

	@Column(name = "total_goal")
	private Integer totalGoal;

	private String location;

	@Column(name = "play_time")
	private Integer playTime;

	@Column(name = "location_full")
	private String locationFull;

	@OneToMany
	private Set<Contract> contracts = new HashSet<Contract>(0);

	@ManyToOne()
	@JoinColumn(name="league_id")
	private League league;

	public Integer getPlayTime() {

		return playTime;
	}

	public void setPlayTime(Integer playTime) {

		this.playTime = playTime;
	}

	public String getLocation() {

		return BASE_SPORT + location.substring(3);
	}

	public void setLocation(String location) {

		this.location = location;
	}

	public String getLocationFull() {

		return locationFull;
	}

	public void setLocationFull(String locationFull) {

		this.locationFull = locationFull;
	}

	public Long getId() {

		return id;
	}

	public void setId(Long id) {

		this.id = id;
	}

	public String getHomeName() {

		return homeName;
	}

	public void setHomeName(String homeName) {

		this.homeName = homeName;
	}

	public String getAwayName() {

		return awayName;
	}

	public void setAwayName(String awayName) {

		this.awayName = awayName;
	}

	public Integer getTotalGoal() {

		return totalGoal;
	}

	public void setTotalGoal(Integer totalGoal) {

		this.totalGoal = totalGoal;
	}

	public String getName() {

		return name;
	}

	public void setName(String name) {

		this.name = name;
	}

	public Set<Contract> getContracts() {

		return contracts;
	}

	public void setContracts(Set<Contract> contracts) {

		this.contracts = contracts;
	}

	public League getLeague() {
		return league;
	}

	public void setLeague(League league) {
		this.league = league;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((awayName == null) ? 0 : awayName.hashCode());
		result = prime * result
				+ ((homeName == null) ? 0 : homeName.hashCode());
		result = prime * result
				+ ((location == null) ? 0 : location.hashCode());
		result = prime * result
				+ ((locationFull == null) ? 0 : locationFull.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Event)) {
			return false;
		}
		Event other = (Event) obj;
		if (awayName == null) {
			if (other.awayName != null) {
				return false;
			}
		} else if (!awayName.equals(other.awayName)) {
			return false;
		}
		if (homeName == null) {
			if (other.homeName != null) {
				return false;
			}
		} else if (!homeName.equals(other.homeName)) {
			return false;
		}
		if (location == null) {
			if (other.location != null) {
				return false;
			}
		} else if (!location.equals(other.location)) {
			return false;
		}
		if (locationFull == null) {
			if (other.locationFull != null) {
				return false;
			}
		} else if (!locationFull.equals(other.locationFull)) {
			return false;
		}
		return true;
	}



}
